import requests
import app
import logging


# 员工管理模块相关接口
class EmpApi:
    def __init__(self):
        # 新增员工URL
        self.add_emp_url = app.BASE_URL + "/api/sys/user"
        # 查询员工URL
        self.query_emp_url = app.BASE_URL + "/api/sys/user/{}"
        # 修改员工URL
        self.update_emp_url = app.BASE_URL + "/api/sys/user/{}"
        # 删除员工URL
        self.delete_emp_url = app.BASE_URL + "/api/sys/user/{}"

    # 新增员工
    def add_emp(self, username, mobile, work_number):
        logging.info("req params username={} mobile={} workNumber={}".format(username, mobile, work_number))
        data = {}
        if username is not None:
            data["username"] = username
        if mobile is not None:
            data["mobile"] = mobile
        if work_number is not None:
            data["workNumber"] = work_number
        return requests.post(self.add_emp_url, headers=app.headers_data, json=data)

    # 查询员工
    def query_emp(self, emp_id):
        url = self.query_emp_url.format(emp_id)
        logging.info("query_emp url={}".format(url))
        return requests.get(url, headers=app.headers_data)

    # 修改员工
    def update_emp(self, emp_id, username):
        url = self.update_emp_url.format(emp_id)
        data = {"username": username}
        return requests.put(url, headers=app.headers_data, json=data)

    # 删除员工
    def delete_emp(self, emp_id):
        url = self.delete_emp_url.format(emp_id)
        return requests.delete(url, headers=app.headers_data)
